package com.rxmvp.rxmvpdemo.RxRetrofit.subscriber;

import com.rxmvp.rxmvpdemo.utils.ToastUtil;

import java.net.ConnectException;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

import retrofit2.adapter.rxjava.HttpException;
import rx.Subscriber;

/**
 * 作者： huangRZ on 2017/1/21. 15:04
 * 邮箱：917647409@qq.com
 */
public abstract class BaseSubscriber<T> extends Subscriber<T> {
    @Override
    public void onCompleted() {

    }

    @Override
    public void onError(Throwable e) {
        if (e instanceof UnknownHostException) {
             ToastUtil.showToast("请打开网络");
        } else if (e instanceof SocketTimeoutException) {
             ToastUtil.showToast( "请求超时");
        } else if (e instanceof ConnectException) {
             ToastUtil.showToast("连接失败");
        } else if (e instanceof HttpException) {
             ToastUtil.showToast("请求异常");
        }else {
              ToastUtil.showToast("其他错误");
        }
        e.printStackTrace();
        onFailure();
    }

    @Override
    public void onNext(T t) {

    }

    @Override
    public void onStart() {
        super.onStart();
    }

    public void onFailure(){

    }

}
